package com.fbinggun.dt.task.conditions;

import com.fbinggun.dt.task.Task;
import com.fbinggun.ma3.event.KillArenaMonsterEnvet;
import com.fbinggun.ma3.monster.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;

import java.sql.SQLException;

public class KillMArena extends Conditions{
    String name;
    String arena;

    public KillMArena(String id, ConfigurationSection config, Task task) {
        super(id, config, task);
    }
    @EventHandler
    public void kill(KillArenaMonsterEnvet envet) throws SQLException, ClassNotFoundException {
        if(isRun(envet.getPlayer())) {
            if (arena == null) {
                addIntegral(envet);
            }else {
                if(arena.equalsIgnoreCase(envet.getArena().getId())){
                    addIntegral(envet);
                    return;
                }
            }
        }
    }

    private void addIntegral(KillArenaMonsterEnvet envet) throws SQLException, ClassNotFoundException {
        Attribute attribute= envet.getMonster().getAttribute();
        if(attribute==null){
            addCount(envet.getPlayer(), 1);
            return;
        }
        if(attribute.getDropTable()==null){
            addCount(envet.getPlayer(), 1);
            return;
        }
        addCount(envet.getPlayer(),attribute.getDropTable().getIntegral());
        return;
    }
}
